var startLong = 106.652024;
var startLat = 26.617221;
var endLong = 106.652024;
var endLat = 26.614221;

var startLongR = 106.652024;
var startLatR = 26.617221;
var endLongR = 106.652024;
var endLatR = 26.614221;
var linesPoints = null;

// 工具栏模式：0-查看点1-标新点2-删除点3-画区域4-清除域5-计算点
var model = 0;

var areaPoint = [];
var points = [
    new BMap.Point(114.00100, 22.550000), new BMap.Point(114.00130, 22.550000),
    new BMap.Point(114.00160, 22.550000), new BMap.Point(114.00200, 22.550000),
    new BMap.Point(114.00300, 22.550500), new BMap.Point(114.00400, 22.550000),
    new BMap.Point(114.00500, 22.550000), new BMap.Point(114.00505, 22.549800),
    new BMap.Point(114.00510, 22.550000), new BMap.Point(114.00515, 22.550000),
    new BMap.Point(114.00525, 22.550400), new BMap.Point(114.00537, 22.549500)
];

var map;   //百度地图对象
var car;   //汽车图标
var label; //信息标签
var centerPoint;
var route;//线路
var timer;     //定时器
var index = 0; //记录播放到第几个point
var flags=0;
var followChk, playBtn, pauseBtn, resetBtn; //几个控制按钮
var myp=[];
var starts;
var ends;

// 切换模式
$('body').on('click', '.layui-btn', function() {
    // 样式改变
    $('.btn-contrail').find('.layui-btn').removeClass('btn-click');
    $(this).addClass('btn-click');
    // 事件监听
    model = $(this).data('model');
    flags=$(this).data('model');
    if(3 == model) {
        $('.BMapLib_Drawing').show();
    } else {
        $('.BMapLib_Drawing').hide();
    }
    // 清除域
    if(4 == model) {
        clearAll();
    }
    // 计算点
    if(5 == model) {

        layer.alert('所选区域点数：' + areaPoint.length, { icon: 6, title: "提示：请先刷新页面，已确保数据正确", offset: "auto", skin: 'layui-layer-molv' });

    }
});

// 定义地图
var mp = new BMap.Map("container");





mp.addControl(new BMap.ScaleControl());
// 地图中心点，并设置级别
mp.centerAndZoom(new BMap.Point(113.82382321677107,34.8257697644788), 17);
mp.addControl(new BMap.OverviewMapControl({
    isOpen: true,
    anchor : BMAP_ANCHOR_BOTTOM_RIGHT, //右下角
    offset : new BMap.Size(1,70) //进一步控制缩放按钮的水平竖直偏移量
}));
mp.addControl(new BMap.ScaleControl({
    isOpen: true,
    anchor : BMAP_ANCHOR_BOTTOM_LEFT, //右下角
    offset : new BMap.Size(1,70) //进一步控制缩放按钮的水平竖直偏移量
}));
//添加地图类型控件;
// mp.addControl(new BMap.MapTypeControl());
var MapTypeControl =  new BMap.MapTypeControl();
MapTypeControl.setAnchor(BMAP_ANCHOR_TOP_RIGHT);

MapTypeControl.setOffset(new BMap.Size(20,70));
mp.addControl(MapTypeControl);
mp.setCurrentCity("贵阳");
// 地图类型，卫星地图
// mp.setMapType(BMAP_HYBRID_MAP);
mp.setMapType( BMAP_NORMAL_MAP);
// 鼠标滚动缩放
mp.enableScrollWheelZoom(true);
// 地图缩放级别
// mp.setZoom(18)

// 请求数据，并渲染地图

//通过DrivingRoute获取一条路线的point
var driving = new BMap.DrivingRoute(mp);
var flag2=0;
var flag3;//记录点位id



function init() {
    flag=1;
    mp.clearOverlays();



    followChk = document.getElementById("follow");
    playBtn = document.getElementById("play");
    pauseBtn = document.getElementById("pause");
    resetBtn = document.getElementById("reset");
    exitBtn = document.getElementById("exit");

    layer.closeAll();
    $('#choice').hide();
    document.getElementById('xx').style.display='none';
    document.getElementById('plarou').style.display='none';
    document.getElementById('controller').style.display='block';//显示控件按钮
    document.getElementById('choicepoint').style.display='none';
    model=0;



    driving.search(new BMap.Point(114.00100, 22.550000), new BMap.Point(113.95100, 22.550000));
    driving.setSearchCompleteCallback(function() {
        //得到路线上的所有point
        points = driving.getResults().getPlan(0).getRoute(0).getPath();
        //画面移动到起点和终点的中间
        centerPoint = new BMap.Point((points[0].lng + points[points.length - 1].lng) / 2, (points[0].lat + points[points.length - 1].lat) / 2);
        mp.panTo(centerPoint);
        //连接所有点

        mp.addOverlay(new BMap.Polyline(points, {strokeColor: "black", strokeWeight: 5, strokeOpacity: 1}));
        route=new BMap.Polyline(points, {strokeColor: "black", strokeWeight: 5, strokeOpacity: 1});
        //巡更人员
        label = new BMap.Label("巡更人员", {offset: new BMap.Size(-20, -20)});
        car = new BMap.Marker(points[0]);
        car.setLabel(label);
        mp.addOverlay(car);

        //点亮操作按钮
        playBtn.disabled = false;
        resetBtn.disabled = false;
    });


    flag2=1;
}

function play() {
    playBtn.disabled = true;
    pauseBtn.disabled = false;
    exitBtn.disabled=true;
    var point = points[index];
    if(index > 0) {
        mp.addOverlay(new BMap.Polyline([points[index - 1], point], {strokeColor: "red", strokeWeight: 1, strokeOpacity: 1}));
    }
    label.setContent("经度: " + point.lng + "<br>纬度: " + point.lat);
    car.setPosition(point);
    index++;
    if(followChk.checked) {
        mp.panTo(point);
    }
    if(index < points.length) {
        timer = window.setTimeout("play(" + index + ")", 200);
    } else {
        playBtn.disabled = true;
        pauseBtn.disabled = true;
        exitBtn.disabled=false;
        mp.panTo(point);
    }
}

function pause() {
    playBtn.disabled = false;
    pauseBtn.disabled = true;
    exitBtn.disabled=false;
    if(timer) {
        window.clearTimeout(timer);
    }
}

function reset() {
    followChk.checked = false;
    playBtn.disabled = false;
    pauseBtn.disabled = true;
    exitBtn.disabled=false;
    if(timer) {
        window.clearTimeout(timer);
    }
    index = 0;
    car.setPosition(points[0]);
    mp.panTo(centerPoint);
}
// 渲染地图坐标点
function renderMap() {
    var markers = [];
    points.forEach(v => {
        // 创建新的坐标点
        const marker = new BMap.Marker(new BMap.Point(v['lng'], v['lat']), {
            icon: ''
        })
        // 为每一个点添加点击事件
        marker.addEventListener('click', function() {
            showPoint(v, marker);
        });
        markers.push(marker)
    })
    // 点聚合
    new BMapLib.MarkerClusterer(mp, {
        markers: markers
    });
}
var flagx=1;
// 监听地图点击事件
mp.addEventListener("click", function(e) {


    var point = e.point;
    if(flagx==1)
        starts=new BMap.Point(point.lng,point.lat);
    ends=new BMap.Point(point.lng,point.lat);
    // 创建信息窗口
    var fd=0;
    console.log("总测试");

    if(9 == model){



        var myP1 = new BMap.Point(point.lng, point.lat);


        var lab1 = new BMap.Label("标记点位序号: "+flagx,{position:myP1});


        lab1.setStyle({
            color : "#666867",
            fontSize : "18px",
            border:"0px",
            background:"transparent"
        });


        if(e.overlay)
        {

            myp.push(myP1);
            mp.addOverlay(lab1);
            flagx++;
        }





    }


    if(11==model)  {
        document.getElementById("gao").value="";
        layer.open({
            type: 1,
            area:['50%','90%'],
            content: $('#gaopoint') ,
            title: ['高风险点位信息编辑', 'font-size:18px;'],
            shade:['0.2','red'],
            cancel:function ss() {
                $('#gaopoint').hide();
                mp.removeOverlay(marker);
            }

        })
        console.log("标记测试点");
        var myIcon = new BMap.Icon("http://api.map.baidu.com/img/markers.png", new BMap.Size(23, 25), {

            imageOffset: new BMap.Size(0, 0 - 12 * 25) // 设置图片偏移使用左侧的图片
            // imageOffset: new BMap.Size(-20, 0 - 10 * 25) // 设置图片偏移使用右侧的图片0-x*25代表使用第x+1张图片

        });
        var marker = new BMap.Marker(new BMap.Point(point.lng, point.lat), { icon: myIcon });

        // 添加点击事件
        console.log(point.lng, point.lat);

        document.getElementById('ss3').value = point.lng;
        document.getElementById('ss4').value = point.lat;


        marker.addEventListener('click', function() {
            showPoint(point, marker);
        });
        // 添加坐标点到地图中
        mp.addOverlay(marker);
        marker.disableMassClear();
        // 将坐标点添加到我们的坐标带你集合中
        points.push(point);
    }
    if(12==model)  {
        document.getElementById("zhong").value="";
        layer.open({
            type: 1,
            area:['50%','85%'],
            content: $('#zhongpoint') ,
            title: ['中风险点位信息编辑', 'font-size:18px;'],
            shade:['0.2','red'],
            cancel:function ss() {
                $('#zhongpoint').hide();
                mp.removeOverlay(marker);
            }
        })
        console.log("标记测试点");
        var myIcon = new BMap.Icon(' E:/xungeng2/xungeng2/src/main/resources/static/img/.png', new BMap.Size(30, 30));
        var marker = new BMap.Marker(new BMap.Point(point.lng, point.lat),{
            icon: myIcon
        });
        // 添加点击事件
        console.log(point.lng, point.lat);

        document.getElementById('ss5').value = point.lng;
        document.getElementById('ss6').value = point.lat;
        marker.addEventListener('click', function() {
            showPoint(point, marker);
        });
        // 添加坐标点到地图中


        mp.addOverlay(marker);
        marker.disableMassClear();





        // 将坐标点添加到我们的坐标带你集合中
        points.push(point);

    }
    if(13==model)  {
        document.getElementById("di").value="";
        layer.open({
            type: 1,
            area:['50%','85%'],
            content: $('#dipoint') ,
            title: ['低风险点位信息编辑', 'font-size:18px;'],
            shade:['0.2','red'],
            cancel:function ss() {
                $('#dipoint').hide();
                mp.removeOverlay(marker);
            }
        })
        console.log("标记测试点");

        var marker = new BMap.Marker(new BMap.Point(point.lng, point.lat));
        // 添加点击事件
        console.log(point.lng, point.lat);

        document.getElementById('ss7').value = point.lng;
        document.getElementById('ss8').value = point.lat;


        marker.addEventListener('click', function() {

            showPoint(point, marker);



        });
        // 添加坐标点到地图中


        mp.addOverlay(marker);
        marker.disableMassClear();





        // 将坐标点添加到我们的坐标带你集合中
        points.push(point);

    }
    // 标新点
    if(1 == model) {


        document.getElementById("create_name1").value="";
        document.getElementById("create_name2").value="";
        document.getElementById("create_name3").value="";
        document.getElementById("create_name4").value="";
        // 创建新的坐标点
        layer.open({
            type: 1,
            area:['50%','85%'],
            content: $('#my_dialog') ,
            title: ['任务点信息编辑', 'font-size:18px;'],
            shade:['0.2','red'],
            cancel:function ss() {
                $('#my_dialog').hide();
                mp.removeOverlay(marker);
            }

        })

        console.log("标记测试点");

        var myIcon = new BMap.Icon("http://api.map.baidu.com/img/markers.png", new BMap.Size(23, 25), {

            imageOffset: new BMap.Size(0, 0 - 12 * 25) // 设置图片偏移使用左侧的图片
       // imageOffset: new BMap.Size(-20, 0 - 10 * 25) // 设置图片偏移使用右侧的图片0-x*25代表使用第x+1张图片

        });
        var marker = new BMap.Marker(new BMap.Point(point.lng, point.lat), { icon: myIcon });
        // 添加点击事件
        console.log(point.lng, point.lat);

        document.getElementById('ss1').value = point.lng;
        document.getElementById('ss2').value = point.lat;


        marker.addEventListener('click', function() {

            showPoint(point, marker);



        });

        // 添加坐标点到地图中

        if(fd==0)
        {
            mp.addOverlay(marker);
            marker.disableMassClear();
        }


        // 将坐标点添加到我们的坐标带你集合中
        points.push(point);

    }
});
function showPoly(pointList){

//循环显示点对象
    for(c=0;c<pointList.length;c++){
        var marker = new BMap.Marker(pointList[c]);

//将途经点按顺序添加到地图上
        var label = new BMap.Label(c+1,{offset:new BMap.Size(20,-10)});
        marker.setLabel(label);
    }

    var  group = Math.floor( pointList.length /11 ) ;
    var mode = pointList.length %11 ;

    var driving = new BMap.DrivingRoute( mp, {onSearchComplete: function(results){
            if (driving.getStatus() == BMAP_STATUS_SUCCESS){
                var plan = driving.getResults().getPlan(0);
                var  num = plan.getNumRoutes();
                layer.msg("模拟点位数目 ："+num);
                for(var j =0;j<num ;j++){
                    var pts= plan.getRoute(j).getPath();    //通过驾车实例，获得一系列点的数组
                    var polyline = new BMap.Polyline(pts);
                    mp.addOverlay(polyline);
                }
            }
        }});
    for(var i =0;i<group;i++){
        var waypoints = pointList.slice(i*11+1,(i+1)*11);
        //注意这里的终点如果是11的倍数的时候，数组可是取不到最后一位的，所以要注意终点-1喔。感谢song141的提醒，怪我太粗心大意了~
        driving.search(pointList[i*11], pointList[(i+1)*11-1],{waypoints:waypoints});//waypoints表示途经点
    }
    if( mode != 0){
        var waypoints = pointList.slice(group*11,pointList.length-1);//多出的一段单独进行search
        driving.search(pointList[group*11],pointList[pointList.length-1],{waypoints:waypoints});
    }

}

function begins(){
    layer.msg("可查看该种方式下的路线所需时间，对人员进行派遣");
    //显示轨迹
    showPoly(myp);
}
function addinitpoint(point)
{

    var marker = new BMap.Marker(new BMap.Point(point.lng, point.lat));


    marker.addEventListener('click', function() {

        showPoint(point, marker);



    });

    mp.addOverlay(marker);
    marker.disableMassClear();
    // 将坐标点添加到我们的坐标带你集合中
    points.push(point);
}

function inits()
{
    $.ajax({

        url:"/api/taskpoint/selectAll",
        method: 'GET',
        contentType: 'application/json',
        dataType: "json",
        crossDomain:true,
        success:function(res) {

            if(res.code == 200) {

                layer.msg("初始化任务点位成功");

                //alert(res.data);

                // alert(JSON.stringify(res.data));

                var obj = JSON.parse(JSON.stringify(res.data));

                //alert(obj.length);

                //alert(obj[0].taskLatitudeX);

                for(var i=0;i<obj.length;i++)
                {
                    //     const marker = new BMap.Marker(new BMap.Point(obj[i].taskLatitudeX, obj[i].taskLongitudeY));
                    //     showPoint(point, marker);
                    //     mp.addOverlay(marker);
                    var pointss= new BMap.Point(obj[i].taskLongitudeY,obj[i].taskLatitudeX ); //将标注点转化成地图上的点
                    addinitpoint(pointss);

                }



            }else{
                layer.msg("初始化失败");
            }

        },

    });

    $.ajax({

        url:"/fx/selectAll",

        method: 'GET',
        contentType: 'application/json',
        dataType: "json",
        crossDomain:true,
        success:function(res) {

            if(res.code == 200) {

                layer.msg("初始化风险点位成功");

                //alert(res.data);

                // alert(JSON.stringify(res.data));

                var obj = JSON.parse(JSON.stringify(res.data));

                //alert(obj.length);

                //alert(obj[0].taskLatitudeX);

                for(var i=0;i<obj.length;i++)
                {
                    //     const marker = new BMap.Marker(new BMap.Point(obj[i].taskLatitudeX, obj[i].taskLongitudeY));
                    //     showPoint(point, marker);
                    //     mp.addOverlay(marker);
                    var pointss= new BMap.Point(obj[i].taskLongitudeY,obj[i].taskLatitudeX ); //将标注点转化成地图上的点
                    addinitpoint(pointss);

                }


            }else{
                layer.msg("初始化失败");
            }

        },

    });


}
function exit(){
    myp=[];
    flagx=1;
    document.getElementById('controller').style.display='none';//显示控件按钮
    mp.clearOverlays();
    reset();
    flag2=0;//退出标志
    flag=1;
}
// 坐标点的点击事件监听
var lngs,lats;
function showPoint(point, marker) {
    // 查看点
    // 创建信息窗口
    var opts = {
        width: 280,
        height: 260 ,


        title: '任务点信息'
    };

    if(0 == model) {

        var lng = point.lng;
        var lat =point.lat;

        var t1,t2,t3,t4,t5;

        $.ajax({

            async:false,
            url:"/api/taskpoint/selectAll",

            method: 'GET',
            contentType: 'application/json',
            dataType: "json",
            crossDomain:true,

            success:function test(res) {

                if(res.code == 200) {
                    var obj = JSON.parse(JSON.stringify(res.data));

                    for(var i=0;i<obj.length;i++) {

                        if(point.lng==obj[i].taskLongitudeY&&point.lat==obj[i].taskLatitudeX)
                        {

                            t1=obj[i].taskName;
                            t2=obj[i].taskType;
                            t3=obj[i].taskAddress;
                            t4=obj[i].taskInfo;
                            t5=obj[i].frequency;
                        }


                    }

                }


                else{
                    layer.msg("参数获取失败");
                }

            },

        });
        lngs=lng;
        lats=lat;
        var infoWindow = new BMap.InfoWindow(`<div style='word-break:break-all;overflow-y:scroll;overflow-x:hidden;height: 220px;'>`+`<br>`+'经纬度'+lng+','+lat+`<br>`+`<br>`+'任务名称:'+t1+`<br>`+'任务类型:'+t2+`<br>`+'任务地址:'+`<br>`+t3+`<br>`+'任务信息:'+`<br>`+t4+`<br>`+'打卡频次:'+t5+`<br>`+`<button style='background-color: #00FF00; margin-top: 20px;margin-left:100px;' onclick="opens(lngs,lats)">编辑信息</button>`+`</div>`, opts);


        // console.log("查看测试");
        // alert('经度：' + lng + '，纬度：' + lat);
        mp.openInfoWindow(infoWindow, point); // 开启信息窗口
    }

    // 删除点
    if(2 == model) {
        var flag3;

        $.ajax({
            async:false,
            url:"/api/taskpoint/selectAll",

            method: 'GET',
            contentType: 'application/json',
            dataType: "json",
            crossDomain:true,

            success:function test(res) {

                if(res.code == 200) {
                    var obj = JSON.parse(JSON.stringify(res.data));
                    for(var i=0;i<obj.length;i++) {

                        if(point.lng==obj[i].taskLongitudeY&&point.lat==obj[i].taskLatitudeX)
                        {

                            flag3=obj[i].taskId;

                        }


                    }

                }


                else{
                    layer.msg("参数获取失败");
                }

            },

        });


        $.ajax({

            url:"/api/taskpoint/" + flag3,

            method: 'DELETE',
            contentType: 'application/json',
            dataType: "json",
            crossDomain:true,
            success:function(res) {

                if(res.code == 200) {

                    layer.msg("删除点位成功");

                }else{
                    layer.msg("删除点位成失败");

                }

            },

        });
        mp.removeOverlay(marker);

    }
}

// 区域坐标点范围
var overlays = [];
// 区域划分后触发事件
var overlaycomplete = function(e) {
    var position = [];
    overlays.push(e.overlay);
    // 获取多边形端点坐标
    for(var i = 0; i < e.overlay.getPath().length; i++) {
        let coordinate = new Object();
        coordinate.lng = e.overlay.getPath()[i].lng;
        coordinate.lat = e.overlay.getPath()[i].lat;
        position.push(coordinate);
    }
    // 清空上一区域内的点
    areaPoint.length = 0;
    // 重新添加区域内的点
    points.forEach(v => {
        // 计算点是否在区域内
        if(isInsidePolygon(v, position)) {
            areaPoint.push(v)
        }
    })
    // 关闭绘制模式
    drawingManager.close();
};

// 绘制样式
var styleOptions = {
    strokeColor: "red", //边线颜色。
    fillColor: "red", //填充颜色。当参数为空时，圆形将没有填充效果。
    strokeWeight: 3, //边线的宽度，以像素为单位。
    strokeOpacity: 0.8, //边线透明度，取值范围0 - 1。
    fillOpacity: 0.6, //填充的透明度，取值范围0 - 1。
    strokeStyle: 'solid' //边线的样式，solid或dashed。
};

// 实例化鼠标绘制工具
var drawingManager = new BMapLib.DrawingManager(mp, {
    // 是否开启绘制模式
    isOpen: false,
    // 是否显示工具栏
    enableDrawingTool: true,
    drawingToolOptions: {
        // 位置
        anchor: BMAP_ANCHOR_TOP_RIGHT,
        // 偏离值
        offset: new BMap.Size(5, 5),
        // 画覆盖物工具栏上显示的可选项
        drawingModes: [
            BMAP_DRAWING_MARKER,
            BMAP_DRAWING_CIRCLE,
            BMAP_DRAWING_POLYLINE,
            BMAP_DRAWING_POLYGON,
            BMAP_DRAWING_RECTANGLE
        ]
    },
    // 圆的样式
    circleOptions: styleOptions,
    // 线的样式
    polylineOptions: styleOptions,
    // 多边形的样式
    polygonOptions: styleOptions,
    // 矩形的样式
    rectangleOptions: styleOptions
});

// 添加鼠标绘制工具监听事件，用于获取绘制结果
drawingManager.addEventListener('overlaycomplete', overlaycomplete);

/// 清除区域
function clearAll() {
    for(var i = 0; i < overlays.length; i++) {
        mp.removeOverlay(overlays[i]);
    }
    // 区域坐标置空
    overlays.length = 0
}

function addpoint() {

    var fields = $('#my_dialog').serializeArray();
    var obj = {}; //声明一个对象
    $.each(fields, function(index, field) {
        obj[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
    })
    $.ajax({
        url:"/api/taskpoint/insertPoint",
        data:JSON.stringify(obj),
        method: 'POST',
        contentType: 'application/json',
        dataType: "json",
        crossDomain:true,
        success:function(res) {

            if(res.code == 200) {
                layer.closeAll();

                $('#my_dialog').hide();
                layer.msg("保存成功");
            }
            else{
                layer.msg("保存失败");
            }
        }
    })
    var g1=document.getElementById("create_name1").value;
    var g2=document.getElementById("create_name2").value;
    var g3=document.getElementById("create_name3").value;
    var g4=document.getElementById("create_name4").value;
    var g5=$("#create_type1").val();

}

//打开窗口
function opens(lng,lat){

    document.getElementById("st1").value=lng;
    document.getElementById("st2").value=lat;
    document.getElementById("create_name1").value="";
    document.getElementById("create_name2").value="";
    document.getElementById("create_name3").value="";
    document.getElementById("create_name4").value="";
    layer.open({
        type: 1,
        area:['50%','95%'],
        content: $('#my_dialog2') ,
        title: ['任务点信息编辑', 'font-size:18px;'],
        shade:['0.2','red'],
        cancel:function ss() {
            $('#my_dialog2').hide();

        }



    })

    var flag4;
    var lngss=document.getElementById("st1").value;
    var latss=document.getElementById("st2").value;
    $.ajax({
        async:false,
        url:"/api/taskpoint/selectAll",

        method: 'GET',
        contentType: 'application/json',
        dataType: "json",
        crossDomain:true,

        success:function test(res) {

            if(res.code == 200) {
                var obj = JSON.parse(JSON.stringify(res.data));
                for(var i=0;i<obj.length;i++) {

                    if(lngss==obj[i].taskLongitudeY&&latss==obj[i].taskLatitudeX)
                    {

                        flag4=obj[i].taskId;

                    }


                }

            }


            else{
                layer.msg("参数获取失败");
            }

        },

    });
    document.getElementById("taskid").value=flag4;

}

function changepoint(){


    var fields = $('#my_dialog2').serializeArray();
    var obj = {}; //声明一个对象

    $.each(fields, function(index, field) {
        obj[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
    })






    $.ajax({
        url:"/api/taskpoint/updatePoint",
        data:JSON.stringify(obj),
        method: 'POST',
        contentType: 'application/json',
        dataType: "json",
        crossDomain:true,
        success:function(res) {

            if(res.code == 200) {

                layer.closeAll();

                $('#my_dialog2').hide();
                layer.msg("保存成功");
            }

            else{
                layer.msg("保存失败");

            }

        }

    })
    var g1=document.getElementById("create_name1").value;
    var g2=document.getElementById("create_name2").value;
    var g3=document.getElementById("create_name3").value;
    var g4=document.getElementById("create_name4").value;
    var g5=$("#create_type1").val();


}
$(document).on( 'click', '#text', function(){
    layer.open({
        type: 2,
        area:['80%','90%'],
        content: "paiqian.html" ,//不想让iframe出现滚动可以content: ['http://sentsin.com', 'no']
        title: ['按巡更id查询', 'font-size:18px;'],
        shade:['0.2','red']
    });
});
$(document).on( 'click', '#fasongxungeng', function(){
    layer.open({
        type: 2,
        area:['80%','90%'],
        content: "fasongxungengluxian.html" ,//不想让iframe出现滚动可以content: ['http://sentsin.com', 'no']
        title: ['按巡更id查询', 'font-size:18px;'],
        shade:['0.2','red']
    });
});


// function text(){
//     var fields = $('#paiqian').serializeArray();
//     var objt = {}; //声明一个对象
//     $.each(fields, function(index, field) {
//         objt[field.name] = field.value; //通过变量，将属性值，属性一起放到对象中
//     })
//
//     $.ajax({
//         url:"/api/user/selectAll",
//         data:JSON.stringify(objt),
//         method: 'POST',
//         contentType: 'application/json',
//         dataType: "json",
//         crossDomain:true,
//         success:function(res) {
//
//             if(res.code == 200) {
//                 layer.msg("显示成功");
//             }
//             else{
//                 layer.msg("显示失败");
//             }
//         }
//     })
//
//
//     layer.open({
//         type: 1,
//         area:['28%','85%'],
//         content: $('#person') ,
//         title: ['巡更人员派遣', 'font-size:18px;'],
//         shade:['0.2','red'],
//         cancel:function ss() {
//             $('#person').hide();
//
//         }
//     })
//
// }

function backs(){
    document.getElementById('begins').disabled=false;
    document.getElementById('xx').style.display='none';
    document.getElementById('plarou').style.display='block';//显示控件按钮
    document.getElementById('controller').style.display='none';
    document.getElementById('choicepoint').style.display='none';

    document.getElementById('setpoint').className='pp';

}
function choosepoint(){
    flag=1;
    document.getElementById('setpoint').className='layui-btn';

    document.getElementById('choicepoint').style.display='block';
    document.getElementById('xx').style.display='none';
    document.getElementById('controller').style.display='none';
    document.getElementById("danger").style.display='none';
    document.getElementById('plarou').style.display='none';
    layer.msg("请选择点位标记");


}

// 计算点是否在坐标内
function isInsidePolygon(point, pts) {
    const N = pts.length
    let intersectCount = 0
    let precision = 2e-10
    // 邻界顶点
    let p1, p2
    let p = point
    // 左顶点
    p1 = pts[0]
    // 检查所有射线
    for(let i = 1; i <= N; ++i) {
        // p是一个边上的点
        if(p.lat === p1.lat && p.lng === p1.lng){
            return true
        }
        // 右顶点
        p2 = pts[i % N]
        // 射线与我们无关
        if(p.lat < Math.min(p1.lat, p2.lat) || p.lat > Math.max(p1.lat, p2.lat)) {
            p1 = p2;
            // 下一个射线左点
            continue;
        }
        if(p.lat > Math.min(p1.lat, p2.lat) && p.lat < Math.max(p1.lat, p2.lat)) {
            if(p.lng <= Math.max(p1.lng, p2.lng)) {
                if(p1.lat === p2.lat && p.lng >= Math.min(p1.lng, p2.lng))
                    return true

                if(p1.lng === p2.lng) {
                    if(p1.lng === p.lng) {
                        return true
                    } else {
                        ++intersectCount
                    }
                } else {
                    let xInters = (p.lat - p1.lat) * (p2.lng - p1.lng) / (p2.lat - p1.lat) + p1.lng;
                    if(Math.abs(p.lng - xInters) < precision)
                        return true

                    if(p.lng < xInters)
                        ++intersectCount
                }
            }
        } else {
            if(p.lat === p2.lat && p.lng <= p2.lng) {
                // 下一个顶点
                let p3 = pts[(i + 1) % N];
                if(p.lat >= Math.min(p1.lat, p3.lat) && p.lat <= Math.max(p1.lat, p3.lat))
                    ++intersectCount
                else
                    intersectCount += 2
            }
        }
        // 下一个射线左点
        p1 = p2
    }
    // 偶数在多边形外, 奇数在多边形内
    return 0 !== intersectCount % 2
}

// 添加带有定位的导航控件
var navigationControl = new BMap.NavigationControl({
    // 靠左上角位置
    anchor: BMAP_ANCHOR_TOP_LEFT,
    // LARGE类型
    offset : new BMap.Size(1,90),
    type: BMAP_NAVIGATION_CONTROL_LARGE,
    // 启用显示定位
    enableGeolocation: true // 会多出一个点
});
mp.addControl(navigationControl);
// 添加定位控件
var geolocationControl = new BMap.GeolocationControl();
geolocationControl.setOffset(new BMap.Size(5,150));

geolocationControl.addEventListener("locationSuccess", function(e){
    // 定位成功事件
    var address = '';
    address += e.addressComponent.province;
    address += e.addressComponent.city;
    address += e.addressComponent.district;
    address += e.addressComponent.street;
    address += e.addressComponent.streetNumber;
    alert("当前定位地址为：" + address);
});
geolocationControl.addEventListener("locationError",function(e){
    // 定位失败事件
    alert(e.message);
});
mp.addControl(geolocationControl);
